package com.amoby.base.commbank.commbiz;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import com.amoby.base.utils.StringUtil;

public class DetailRecord {
    // 固定填充的字符串
    private static final String     RECORD_TYPE = "1";
    private static final BigDecimal DECIMAL_100 = new BigDecimal(100);
    /** 账户类型（1：收款账户， 2：付款账户） */
    private int                     detailType  = DirectEntryFile.DETAIL_TYPE_CREDIT;
    /** BSB Number 开户行编号 */
    private String                  bsbNumber;
    /** 银行账户号 */
    private String                  accountNumber;
    /** 银行账户名 */
    private String                  accountTitle;
    /** 税率标志（在此业务中常为N） */
    private String                  indicator;
    /** 账户用途（在此业务中credit:50,debit:13） */
    private String                  transactionCode;
    /** 金额 */
    private Double                  amount;
    /** 支付流水号 */
    private String                  lodgementReference;
    /** BSB Number 开户行编号 */
    private String                  traceBSBNumber;
    /** 银行账户号 */
    private String                  traceAccountNumber;
    /** 汇款人 */
    private String                  remitterName;
    /** 税（在此业务中常为0） */
    private Double                  tax;

    public static void main(String[] args) {
        String bsbNumber2 = "001000";
        NumberFormat bsbFormat = new DecimalFormat("000,000");
        String.format("", 1);
        String string = bsbFormat.format(Long.parseLong(bsbNumber2));
        System.out.println(string);
    }

    /**
     * 将信息序列化为字符串
     * 
     * @return 序列化结果
     * @throws IllegalArgumentException 信息有误
     */
    public String serialize() throws IllegalArgumentException {
        StringBuffer sb = new StringBuffer();
        // 序列化常量字符
        sb.append(RECORD_TYPE);
        // 序列化数据字段
        StringUtil.assertSizeEq(bsbNumber, 6);
        sb.append(DirectEntryFile.NUM_FORMAT.format(Long.parseLong(bsbNumber)).replace(',', '-'));
        sb.append(StringUtil.rightJustified(accountNumber, 9));
        StringUtil.assertSizeEq(indicator, 1);
        sb.append(indicator);
        // switch (detailType) {
        // case DirectEntryFile.DETAIL_TYPE_CREDIT:
        // transactionCode = "50";
        // break;
        // case DirectEntryFile.DETAIL_TYPE_DEBIT:
        // transactionCode = "13";
        // break;
        // default:
        // throw new IllegalArgumentException("detailType值不正确");
        // }
        StringUtil.assertSizeEq(transactionCode, 2);
        sb.append(transactionCode);
        // 序列化金额， 将double金额转换为以分为单位的integer数据
        sb.append(StringUtil.rightJustified(String.valueOf(new BigDecimal(amount.toString()).multiply(DECIMAL_100).intValue()), 10, "0"));
        sb.append(StringUtil.leftJustified(accountTitle, 32));
        sb.append(StringUtil.leftJustified(lodgementReference, 18));
        StringUtil.assertSizeEq(traceBSBNumber, 6);
        sb.append(DirectEntryFile.NUM_FORMAT.format(Long.parseLong(traceBSBNumber)).replace(',', '-'));
        sb.append(StringUtil.rightJustified(traceAccountNumber, 9));
        sb.append(StringUtil.leftJustified(remitterName == null ? "" : remitterName, 16));
        sb.append(StringUtil.rightJustified(String.valueOf(new BigDecimal(tax.toString()).multiply(DECIMAL_100).intValue()), 8, "0"));
        return sb.toString();
    }

    public String getLodgementReference() {
        return this.lodgementReference;
    }

    public void setLodgementReference(String lodgementReference) {
        this.lodgementReference = lodgementReference;
    }

    public int getDetailType() {
        return this.detailType;
    }

    public void setDetailType(int detailType) {
        this.detailType = detailType;
    }

    public String getBsbNumber() {
        return this.bsbNumber;
    }

    public String getAccountNumber() {
        return this.accountNumber;
    }

    public String getAccountTitle() {
        return this.accountTitle;
    }

    public String getIndicator() {
        return this.indicator;
    }

    public String getTransactionCode() {
        return this.transactionCode;
    }

    public Double getAmount() {
        return this.amount;
    }

    public String getTraceBSBNumber() {
        return this.traceBSBNumber;
    }

    public String getTraceAccountNumber() {
        return this.traceAccountNumber;
    }

    public String getRemitterName() {
        return this.remitterName;
    }

    public Double getTax() {
        return this.tax;
    }

    public void setBsbNumber(String bsbNumber) {
        this.bsbNumber = bsbNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public void setAccountTitle(String accountTitle) {
        this.accountTitle = accountTitle;
    }

    public void setIndicator(String indicator) {
        this.indicator = indicator;
    }

    public void setTransactionCode(String transactionCode) {
        this.transactionCode = transactionCode;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public void setTraceBSBNumber(String traceBSBNumber) {
        this.traceBSBNumber = traceBSBNumber;
    }

    public void setTraceAccountNumber(String traceAccountNumber) {
        this.traceAccountNumber = traceAccountNumber;
    }

    public void setRemitterName(String remitterName) {
        this.remitterName = remitterName;
    }

    public void setTax(Double tax) {
        this.tax = tax;
    }
}
